# Makefile
# $Id: Makefile 23735d82d7e1 2012/12/05 00:40:38 pgurumur $
# Copyright (c) 2013 Prabhu Gurumurthy <pgurumur@gmail.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# File Makefile generated on Sunday June 09, 2013 @01:07:50 PDT
#
# __version__  = "$Revision: 23735d82d7e1 $"
# __author__   = "$Author: pgurumur $"
# __modified__ = "$Date: 2012-12-05 00:40:38Z $"

PROG	:= test
UNAME := $(shell uname)
INC	:= $(HOME)/apps/include
LIBS	:= $(HOME)/apps/lib
NVCC := nvcc
GCC := g++

CFLAGS	:= -m64 -I$(INC) -I.
LDFLAGS	:= -L$(LIBS)  -lcudart
NVCCFLAGS	:= $(CFLAGS)

ENCODE_SM10	:= -gencode arch=compute_10,code=sm_10
GENCODE_SM20	:= -gencode arch=compute_20,code=sm_20
GENCODE_SM30	:= -gencode arch=compute_30,code=sm_30 
GENCODE_SM30 += -gencode arch=compute_35,code=sm_35
GENCODE_FLAGS	:= $(GENCODE_SM10) $(GENCODE_SM20) $(GENCODE_SM30)

CUDA_OBJS	:= $(patsubst %.cu,%.co,$(wildcard *.cu))
OBJS	:=	$(patsubst %.c,%.o,$(wildcard *.c))
CPP_OBJS :=	$(patsubst %.cpp,%.o,$(wildcard *.cpp))
CPP_OBJS	+=	$(patsubst %.cc,%.o,$(wildcard *.cc))

DEBUG ?= 1
ifeq (DEBUG, 1)
	CFLAGS += -g
	NVCCFLAGS += -g -G
else
	CFLAGS	+=
	NVCCFLAGS	+=
endif

RM	:= /bin/rm -f

all: build

build: $(PROG)

%.co: %.cu
	@echo "$(NVCC) compiling $<"
	@$(NVCC) $(NVCCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<

$(PROG): $(CUDA_OBJS)
	@echo "$(CC) compiling $+"
	@$(GCC) $(CFLAGS) -o $@ $+ $(LDFLAGS)

clean:
	@echo "cleaning... $(PROG) $(CUDA_OBJS) $(OBJS) $(CPP_OBJS)"
	@$(RM) $(PROG) $(CUDA_OBJS) $(OBJS) $(CPP_OBJS)

run: build
	./$(PROG)

